<?php
namespace api\modules\v1\models\userLevel;

use api\modules\v1\models\Common;
use api\modules\v1\models\user\User;
use common\models\Functions;
use common\models\Status;
use yii\base\Exception;
use Yii;
/**
 * Class UserLevel
 * @package api\modules\v1\models\user
 */
class UserLevel extends \common\models\userLevel\UserLevel
{

    //级别列表
    public function getList() {
        try {
//            $user = Yii::$app->getUser()->getIdentity()->toArray();
            $user = (new User())->checkUserNoExp();

            $where['status'] = Status::COMMON_STATUS_SHOW;
            $andWhere[] = ['>','id',1];
            $list = static::getByAndWhere($where,$andWhere);

            $tmp = [];
            foreach ($list as $key => $value) {
                $tmp[] = [
                    'id' => (int) $value['id'],
                    'user_face' => $user ? static::getImages($user['use_face']) : static::getImages(),
                    'name' => $value['name'],
                    'current_level' => $user ? $value['id'] == $user['level_id'] : false,
                    'expire_time' => ($user && $value['id'] == $user['level_id']) ? $user['level_expire_time'] : '未开通',
                    'money' => json_decode($value['money'],true),
                    'interests' => json_decode($value['interests'],true),
                ];
            }
            return Functions::formatRestAPI(0, '', $tmp);
        } catch ( Exception $e ) {
            return Functions::formatRestAPI(1, $e->getMessage());
        }
    }

}
